package com.aefottt.struggle_star;

import android.content.Context;

import com.aefottt.struggle_star.activity.DataActivity;
import com.aefottt.struggle_star.bean.TaskBean;

public class DataListenerManager {
    private DataActivity.OnDataActivityListener listener;
    private Context context;
    private static DataListenerManager manager;

    public static DataListenerManager getInstance(Context context){
        if (manager == null){
            synchronized (DataListenerManager.class){
                if (manager == null){
                    manager = new DataListenerManager(context);
                }
            }
        }
        return manager;
    }

    private DataListenerManager(Context context) {
        // 使用getApplicationContext()防止单例模式内存泄漏
        this.context = context.getApplicationContext();
    }

    public void setListener(DataActivity.OnDataActivityListener listener) {
        this.listener = listener;
    }

    public void onDelete(TaskBean taskBean){
        if (listener != null){
            listener.onDelete(taskBean);
        }
    }

    public void onCreate(TaskBean taskBean){
        if (listener != null){
            listener.onCreate(taskBean);
        }
    }
}
